// lib/users.js
import {db} from './db'
import {hash, compare} from "bcrypt";

export async function createUser({email, name, password}) {
    const passwordHash = await hash(password, 10) // 加盐
    return await db.user.create({
        data: {email, name, passwordHash, desc: '该用户没有填写简介哦'}
    })
}

export async function authenticateUser(email, password) {
    const user = await db.user.findUnique({
        where: {email}
    })
    if (user && await compare(password, user.passwordHash)) {
        return user
    }
}